package com.founder.android.reader.util;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import com.founder.android.reader.bean.ZipPicture;

public class ZipUtil {
	
	public static List<ZipPicture> getPictureFromZip(String zipFilePath) throws IOException {
		ZipFile zip = new ZipFile(zipFilePath);
		ArrayList<ZipPicture> list = new ArrayList<ZipPicture>();
		Enumeration<? extends ZipEntry>  e = zip.entries();
		while (e.hasMoreElements()) {
			ZipEntry entry = e.nextElement();
			String name = entry.getName();
			System.out.println(name);
			if(name.endsWith(".jpg")||name.endsWith(".png")){
				Bitmap bmp = BitmapFactory.decodeStream(zip.getInputStream(entry));
				ZipPicture zp = new ZipPicture(name,bmp);
				list.add(zp);
			}
		}
		return list;
	}

}
